//
//  AppDelegate.m
//  Pennyworth Example
//
//  Created by Chris Karr on 4/17/08.
//  Copyright 2008 Northwestern University. All rights reserved.
//

#import "AppDelegate.h"

#define COCOA_OBSERVATION @"Pennyworth: Cocoa Observation"
#define COCOA_OBSERVER @"Pennyworth: Cocoa Observer"
#define COCOA_OBSERVATION_VALUE @"Pennyworth: Cocoa Observation Value"
#define COCOA_OBSERVATION_DURATION @"Pennyworth: Cocoa Observation Duration"
#define PREDICTION_FETCHED @"Prediction Fetched"
#define KEY @"Key"
#define PREDICTION @"Prediction"

@implementation AppDelegate

- (void) awakeFromNib
{
	[[NSDistributedNotificationCenter defaultCenter] addObserver:self 
													 selector:@selector(process:) 
													 name:PREDICTION_FETCHED
													 object:nil];
													 
	[[NSTimer scheduledTimerWithTimeInterval:30.0 target:self 
												  selector:@selector(log:) 
												  userInfo:nil repeats:YES] retain];
}

- (void) process:(NSNotification *) theNote
{
	NSString * key = [[theNote userInfo] valueForKey:KEY];
	NSString * prediction = [[theNote userInfo] valueForKey:PREDICTION];
	
	NSLog (@"%@ = %@", key, prediction);
}

- (void) log:(NSTimer *) theTimer
{
	NSMutableDictionary * note = [NSMutableDictionary dictionary];

	[note setValue:[[NSDate date] description] forKey:COCOA_OBSERVATION_VALUE];
	[note setValue:@"Example Cocoa Sensor" forKey:COCOA_OBSERVER];
	[note setValue:[NSNumber numberWithInt:10] forKey:COCOA_OBSERVATION_DURATION];
	
	[[NSDistributedNotificationCenter defaultCenter] postNotificationName:COCOA_OBSERVATION 
													 object:@"net.aetherial.PennyworthExample" userInfo:note];
}

@end
